/**
 * FireFly (2011)
 */
package com.firefly.logging;

/**
 * 抽象Logger插件
 * 
 * @version 1.0 2011-1-1
 * @author lexloo(lexloo@gmail.com)
 * @since FireFly 1.0
 */
public abstract class AbstractLoggerPluginInstance implements ILoggerPluginInstance {
	private final Logger logger;
	private final ILoggerPlugin loggerPlugin;

	public AbstractLoggerPluginInstance(final String name, final ILoggerPlugin loggerPlugin) {
		this.loggerPlugin = loggerPlugin;

		logger = new Logger(name, this);
	}

	@Override
	public ILoggerPlugin getLoggerPlugin() {
		return loggerPlugin;
	}

	@Override
	public Logger getLogger() {
		return logger;
	}

	@Override
	public void log(final Logger.Level level, final String loggerFqcn, final Object message, final Object... params) {
		if (isEnabled(level)) {
			final String msgStr = String.valueOf(message);
			if (params.length > 0) {
				log(level, loggerFqcn, String.format(msgStr, params));
			} else {
				log(level, loggerFqcn, msgStr);
			}
		}
	}

	protected abstract void log(final Logger.Level level, final String loggerFqcn, final String message);
}